﻿using System;
using System.Linq;
using System.ServiceModel.DomainServices.Client;
using System.Windows;
using System.Windows.Controls;
using GSSoftSL.ViewModel;
using GSSoftSL.Web.Models;

namespace GSSoftSL.Views
{
    /// <summary>
    /// Description for KhoaHocView.
    /// </summary>
    public partial class KhoaHocViewOld : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the KhoaHocView class.
        /// </summary>
        public KhoaHocViewOld()
        {
            InitializeComponent();
            //DataGrid dg = new DataGrid();
            //gridLayout.
            //dataForm.Mode == 
        }

        private void DataForm_ContentLoaded(object sender, DataFormContentLoadEventArgs e)
        {
            if (e.Mode == DataFormMode.AddNew)
            {
                KhoaHocViewModelOld vm = (KhoaHocViewModelOld) DataContext;
                KhoaHoc kh = dataForm.CurrentItem as KhoaHoc;
                kh.BatDau = DateTime.Now.Date;
                kh.KetThuc = kh.BatDau.AddMonths(1);
                //kh.MaKhoaHoc = "";

                //vm.DC.EntityContainer.GetEntitySet<KhoaHoc>().Add(kh);
                //vm.CurrentLop.KhoaHocs.Add(dataForm.CurrentItem as KhoaHoc);
            }
        }

        private void dataForm_DeletingItem(object sender, System.ComponentModel.CancelEventArgs e)
        {
            KhoaHocViewModelOld vm = (KhoaHocViewModelOld)DataContext;
        }

        private void dataForm_EditEnding(object sender, DataFormEditEndingEventArgs e)
        {
            if (e.EditAction == DataFormEditAction.Cancel)
            {
                KhoaHocViewModelOld vm = (KhoaHocViewModelOld)DataContext;
                KhoaHoc kh = dataForm.CurrentItem as KhoaHoc;
                //vm.CurrentLop.KhoaHocs.Remove(kh);
                //vm.DC.RejectChanges();
                //bool tmp = vm.CurrentLop.KhoaHocs.Contains(kh);
                //vm.CurrentLop.KhoaHocs.Remove(kh);
                //dataForm.CancelEdit();
            }
        }

        private void dataForm_EditEnded(object sender, DataFormEditEndedEventArgs e)
        {
            /*if (e.EditAction == DataFormEditAction.Cancel)
            {
                KhoaHoc kh = dataForm.CurrentItem as KhoaHoc;
            }
            else
            {
                ((KhoaHocViewModel)DataContext).Save();
            }*/
        }

        private void dtpBatDau_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            DatePicker dp = sender as DatePicker;
            ((KhoaHocViewModelOld) this.DataContext).CurrentKhoaHoc.BatDau = dp.SelectedDate.Value;
        }
    }
}